<% availableModels ||= available_models %>
<%canBeDownloaded = !document.getDownloadUrl(self).nil? %>
<!-- Only documents with an embed partial can be embeded -->
<%canBeEmbeded = lookup_context.template_exists?("embedcode", document.class.to_s.underscore.pluralize, true) %>

<% if canBeEmbeded %>
  <%content_for :javascript do%>
      var embedEvents = false;

      $('a[data-toggle="tab"]').on('shown.bs.tab', function(e){
            if(!embedEvents){
              embedEvents = true;

              $('button#btn_copy_embed').zclip({
                path:'/assets/ZeroClipboard.swf',
                copy:function(){
                  return $('#textarea_for_iframe').val();
                },
                afterCopy: function(){}
              });

              $(".shortUrl").mouseup(function(e){
                // fixes safari/chrome problem
                e.preventDefault();
              }).focus(function(e){
                mytxt = $(this).text();
                $(this).select();
              }).click(function(e){
                mytxt = $(this).text();
                $(this).select();
              });
            }
      });
      $('[data-toggle="tooltip"], .with_tooltip').tooltip({ placement: 'bottom'});
  <%end%>
<%end%>


<script type="text/javascript">
  document.addEventListener("DOMContentLoaded", function(){
    $(".with_tooltip").tooltip({ placement: 'bottom', container:'body'});
  });
</script>


<div class="btn-group">
  <% if can? :destroy, document %>
    <%= link_to raw("<i class='fa fa-trash-o'></i> "),  document,
    confirm: t('confirm_delete', scope: document.class.to_s.underscore),
    title: t('document.actions.delete'),
    method: :delete,
    rel: "tooltip",
    class: "btn with_tooltip" %>
  <% end %>


  <!--Favorite-->
  <% unless document.post_activity.nil? %>
    <%= link_like(document.post_activity, {:size => :big, :class=>'btn', :title =>t('excursion.actions.favorite')})%>
  <%end%>

  <%if user_signed_in? and availableModels.include? "Category" %>
    <%= render partial: 'categories/category_modal_viewer', :locals => {:remote=> true, :item => resource} %>
    <button id="AddCategory" role="button" class="categorize_select btn with_tooltip" data-toggle="modal" data-target="#categories_viewer_modal" title="<%=t('category.modalLabel')%>" aria-hidden="true" ><i class="fa fa-th-large"></i></button>
  <%end%>

</div>

  <ul class="nav nav-tabs">
    <li class="<%= document_details_tab_class document, :info %>">
      <%= link_to (raw("<i class='fa fa-align-left'></i> <span class='hidden-xs'>")) +  t('document.details.info') + raw("</span>"), '#document-info', 'data-toggle' => 'tab' %>
    </li>

    <% if can? :update, document %>
      <li class="<%= document_details_tab_class document, :edit %>">
        <%= link_to (raw("<i class='fa fa-edit'></i> <span class='hidden-xs'>")) + t('document.actions.edit')+ raw("</span>"), '#document-edit', 'data-toggle' => 'tab' %>
      </li>
    <% end %>

    <% if canBeEmbeded %>
      <li class="<%= document_details_tab_class document, :embed %>">
          <%= link_to (raw("<i class='fa fa-code'></i> <span class='hidden-xs'>")) + t('excursion.actions.embed')+ raw("</span>"), '#document-embed', 'data-toggle' => 'tab' %>
      </li>
    <%end%>

    <%if canBeDownloaded %>
      <li class="<%= document_details_tab_class document, :download %>">
          <%= link_to (raw("<i class='fa fa-download'></i> <span class='hidden-xs'>")) + t('document.actions.download')+ raw("</span>"), '#document-download', 'data-toggle' => 'tab' %>
      </li>
    <% end %>

    <li>
      <a href="#tab3" data-toggle="tab">
        <i class="fa fa-flag"></i>
          <span class="hidden-xs">
            <%=t('excursion.actions.spam')%>
          </span>
      </a>
    </li>

    <%= render partial: 'help/help_show_resource' %>
  </ul>


<h1><%= document.title %></h1>

<div class="tab-content">

  <div class="tab-pane <%= document_details_tab_class document, :info %>" id="document-info">
    <div class="toggler">
      <%= render partial: "common_documents/info", locals: { document: document } %>
    </div>
  </div>

  <% if can? :update, document %>
    <div class="tab-pane <%= document_details_tab_class document, :edit %>" id="document-edit">
      <div class="content_edit">
        <%= render partial: 'common_documents/form', locals: { document: document } %>
      </div>
    </div>
  <% end %>

  <% if canBeEmbeded %>
    <div class="tab-pane contentembed <%= document_details_tab_class document, :embed %>" id="document-embed">
      <p class="documentembedexplanation"><%=t("document.embed_explanation")%></p>
      <div class="form-group">
        <div class="input-group">
          <textarea class="shortUrl form-control" readonly="true" rows="6" id="textarea_for_iframe" type="text"><%= render partial: "#{ document.class.to_s.tableize }/embedcode", locals: { document.class.to_s.underscore.to_sym => document } %></textarea>
          <div class="input-group-addon">
            <div data-toggle="tooltip" data-placement="right" title="<%=t('copy_to_clip')%>">
              <button id="btn_copy_embed" href="#">
                <i class="fa fa-copy"></i>
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  <% end %>

  <%if canBeDownloaded %>
    <div class="tab-pane <%= document_details_tab_class document, :download %>" id="document-download">
      <div class="toggler">
        <% if document.respond_to?("zipurl") %>
          <% downloadPath = document.zipurl %>
        <% else %>
          <% downloadPath = download_document_path(document) %>
        <% end %>
        <a class="btn btn-primary" href='<%=downloadPath%>'><i class="fa fa-download"></i> <%=t('document.actions.download')%></a>
      </div>
    </div>
  <% end %>

  <div class="tab-pane" id="tab3">
    <%@activity_object = document.activity_object%>
    <%= render '/spam_report/form' %>
  </div>

</div>
